package com.lyx.crm.controller;

import com.lyx.crm.base.BaseController;
import com.lyx.crm.service.PermissionService;
import com.lyx.crm.service.UserService;
import com.lyx.crm.utils.LoginUserUtil;
import com.lyx.crm.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Package: com.lyx.crm
 * @ClassName: IndexController
 * @Author: lyx
 * @CreateTime: 2021/7/15 11:14
 * @Description:
 */
@Controller
public class IndexController extends BaseController {


    @Autowired
    private UserService userServie;
    @Autowired
    private PermissionService permissionService;

    /**
     * * 系统登录页
     * * @return
     *    
     */
    @RequestMapping("index")
    public String index() {
        return "index";
    }

    // 系统界面欢迎页
    @RequestMapping("welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * * 后端管理主页面
     * * @return
     *    
     */
    @RequestMapping("main")
    public String main(HttpServletRequest request) {

        //通过工具类获取cookie中的UserId
        int userId = LoginUserUtil.releaseUserIdFromCookie(request);
        //查询用户对象，设置Session作用域
        User user = userServie.selectByPrimaryKey(userId);
        request.getSession().setAttribute("user", user);

        List<String> permission = permissionService.queryUserHasRolePermissionByUserId(userId);
        //将集合设置到session作用域中
        request.getSession().setAttribute("permission", permission);
        return "main";
    }
}